<?php
namespace App\Http\Controllers\Api;

use App\Model\Users;
use App\Services\Facades\Sms;
use Illuminate\Http\Request;

class LoginController extends BaseController{

    public function smsLogin(Request $request){
        $rules = [
            'code'  => 'required|size:4',
            'phone' => 'required|regex:/^1[3456789][0-9]{9}$/',
        ];
        $this->validate($request,$rules);
        $verifyCode = $request->code;
        $phone      = $request->phone;

        if( !Sms::checkVerifyCode($phone, $verifyCode) ){
            return $this->failed('验证码错误或已过期');
        }
        $user  = Users::getUserByPhone($phone , true);
        $token = auth()->login($user);
        return $this->success(['access_token'=>$token]);

    }




    public function passLogin(Request $request){
        $rules = [
            'password'  => 'required',
            'phone' => 'required|regex:/^1[3456789][0-9]{9}$/',
        ];
        $this->validate($request,$rules);
        $password = $request->password;
        $phone  = $request->phone;
    }
}
